<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: class.message_stack.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.' );

class message_stack {
	var $size = 0;

	function message_stack() {

		$this->errors = array();

		if (isset($_SESSION['messageToStack'])) {
			for ($i = 0, $n = sizeof($_SESSION['messageToStack']); $i < $n; $i++)
				$this->add($_SESSION['messageToStack'][$i]['text'], $_SESSION['messageToStack'][$i]['type']);

			unset($_SESSION['messageToStack']);
		}
	}

	function add($message, $type = 'error') {

		if ($type == 'error')
			$this->errors[] = array('title' => 'Fehler', 'image' => DIR_WS_ICONS.'dialog-error.png', 'text' => $message);
		elseif ($type == 'warning')
			$this->errors[] = array('title' => 'Warnung', 'image' => DIR_WS_ICONS.'dialog-warning.png', 'text' => $message);
		elseif ($type == 'success')
			$this->errors[] = array('title' => 'Erfolg', 'image' => DIR_WS_ICONS.'dialog-success.png', 'text' => $message);
		else
			$this->errors[] = array('title' => 'Fehler', 'text' => $message);
		$this->size++;
	}

	function add_session($message, $type = 'error') {
		if(!isset($_SESSION['messageToStack']))
			$_SESSION['messageToStack'] = array();

		$_SESSION['messageToStack'][] = array('text' => $message, 'type' => $type);
	}

	function reset() {
		$this->errors = array();
		$this->size = 0;
	}

	function output() {
		$j = '';
		$msg = $this->errors;
		for ($i = 0, $n = sizeof($msg); $i < $n; $i++) {
			$j .= '$.gritter.add({'."\n";
			$j .= '		title: \''.$msg[$i]['title'].'\','."\n";
			$j .= '		text: \''.str_replace('\'', '"', $msg[$i]['text']).'\','."\n";
			$j .= '		image: \''.$msg[$i]['image'].'\','."\n";
			$j .= '		sticky: false,'."\n";
			$j .= '		time: 4000'."\n";
			$j .= '});'."\n";
		}
		return $j;
	}
}
?>